<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { HomeFilled, Edit, ChatDotRound, Setting, Sunny, Moon } from '@element-plus/icons-vue'
import { useThemeStore } from '@/stores/theme'
import { useLoadingStore } from '@/stores/loading'
import '@/styles/theme.scss'

const route = useRoute()
const activeIndex = computed(() => route.path)

// 主题管理
const themeStore = useThemeStore()
const theme = computed(() => themeStore.theme)
const toggleTheme = () => themeStore.toggleTheme()

// 加载状态管理
const loadingStore = useLoadingStore()
const isLoading = computed(() => loadingStore.isLoading)
const loadingText = computed(() => loadingStore.loadingText)

// 初始化
onMounted(() => {
  themeStore.initTheme()
})
</script>

<template>
  <div class="app-container">
    <header class="header">
      <div class="header-content">
        <h1 class="logo">混元智能体</h1>
        <nav class="nav-menu">
          <router-link to="/" class="nav-item">
            <el-icon><HomeFilled /></el-icon>
            首页
          </router-link>
          <router-link to="/prompt" class="nav-item">
            <el-icon><Edit /></el-icon>
            提示词生成
          </router-link>
          <router-link to="/chat" class="nav-item">
            <el-icon><ChatDotRound /></el-icon>
            AI 对话
          </router-link>
          <router-link to="/settings" class="nav-item">
            <el-icon><Setting /></el-icon>
            设置
          </router-link>
        </nav>
        <div class="theme-switch">
          <el-button
            :icon="theme === 'light' ? 'Sunny' : 'Moon'"
            circle
            @click="toggleTheme"
          />
        </div>
      </div>
    </header>

    <main class="main-content">
      <router-view v-slot="{ Component }">
        <component :is="Component" />
      </router-view>
    </main>

    <el-loading
      v-model="isLoading"
      :lock="true"
      :text="loadingText"
      background="rgba(255, 255, 255, 0.8)"
    />
  </div>
</template>

<style>
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  background-color: #f5f7fa;
}

.app-container {
  min-height: 100vh;
}

.header {
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.1);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
}

.logo {
  font-size: 20px;
  font-weight: bold;
  color: #409EFF;
  margin: 0;
  padding-right: 40px;
}

.nav-menu {
  flex: 1;
  display: flex;
  gap: 20px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #606266;
  text-decoration: none;
  font-size: 14px;
  padding: 0 12px;
  height: 60px;
  line-height: 60px;
}

.nav-item:hover,
.nav-item.router-link-active {
  color: #409EFF;
}

.theme-switch {
  margin-left: 20px;
}

.main-content {
  padding-top: 80px;
  min-height: calc(100vh - 80px);
}

@media (max-width: 768px) {
  .header-content {
    padding: 0 15px;
  }

  .logo {
    font-size: 18px;
    padding-right: 20px;
  }

  .nav-menu {
    gap: 10px;
  }

  .nav-item {
    padding: 0 8px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .nav-item span {
    display: none;
  }
  
  .nav-item .el-icon {
    font-size: 20px;
  }
}
</style>
